<!--
 * @Description: 02-10进制转换二进制
 * @Autor: wangxin
 * @Date: 2020-06-10 08:55:12
 * @LastEditors: Seven
 * @LastEditTime: 2020-06-10 08:55:57
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script src="./stack.js"></script>
    <script>
      function decimalToBinary(decimalNumber) {
        const remStack = new Stack()
        let number = decimalNumber
        let rem
        let binaryString = ''

        while (number > 0) {
          rem = Math.floor(number % 2)
          remStack.push(rem)
          number = Math.floor(number / 2)
        }

        while (!remStack.isEmpty()) {
          binaryString += remStack.pop().toString()
        }

        return binaryString
      }

      // 代码测试
      // console.log(decimalToBinary(10))
    </script>
  </body>
</html>
